/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */

package org.jaxson.struts.logging;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Date;

import org.jaxson.struts.BaseAction;

import flexjson.JSONDeserializer;

/**
 * Struts action which receives remote log events and appends
 * them to the server log.
 * 
 * @author Joe Maisel
 */
public class RemoteLoggerAction extends BaseAction
{
	private static final Log lager = LogFactory.getLog( RemoteLoggerAction.class.getName() );

	/**
	 * @see org.jaxson.struts.BaseAction#handle()
	 */
	@Override
	public String handle()
	{
		String msgs = request.getParameter( "messages" );
		JSONDeserializer<ClientLogBatch> ds = new JSONDeserializer<ClientLogBatch>();
		ClientLogBatch batch = ds.deserialize( msgs );

		for( JavascriptLogEntry entry : batch.getEntries() )
		{
			lager.info( new Date( entry.getOccuredOn() ) + ": " + entry.getMessage() );
		}

		return null;
	}

	private static final long serialVersionUID = 1567890957890789098L;
}
